// sm3_hmac.c
#include <stdio.h>
#include <stdlib.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include "utils.h"

int main(int argc, char *argv[]) {
    if (argc != 3) {
        fprintf(stderr, "Usage: %s <input_file> <key_file>\n", argv[0]);
        exit(1);
    }

    size_t data_len, key_len;
    unsigned char *data = read_file(argv[1], &data_len);
    unsigned char *key = read_file(argv[2], &key_len);

    unsigned char dgst[32];
    if (!HMAC(EVP_sm3(), key, key_len, data, data_len, dgst, NULL)) {
        fprintf(stderr, "SM3-HMAC failed.\n");
        exit(1);
    }

    for (int i = 0; i < 32; i++) {
        printf("%02x", dgst[i]);
    }
    printf("\n");

    free(data);
    free(key);
    return 0;
}
